#include "SDFSign.h"

namespace xpm {
	SDFSign::SDFSign(int type): _s_start(-1),
		_s_end(-1),
		_v_start(-1),
		_v_end(-1),
		_parent(0),
		_next_sign(0){
		set_type(type);
	}
	void SDFSign::set_type(int type) {
		_type = type;
		_reification.set_type(type);
		_connotation.set_type(type);
		_next = end();
	}
	// construct with different reification types
	SDFSign::SDFSign(wstring de_str, wstring rei_str): _s_start(-1),
		_s_end(-1),
		_v_start(-1),
		_v_end(-1),
		_parent(0), 
		_next_sign(0){
		_reification.set_type(SDF_STRING);
		_denotation.set_de_str(de_str);
		_reification.set_string(rei_str);
		_next = end();
	}
	SDFSign::SDFSign(wstring de_str, float rei_num): _s_start(-1), 
		_s_end(-1),
		_v_start(-1),
		_v_end(-1),
		_parent(0),
		_next_sign(0){
		_reification.set_type(SDF_NUMBER);
		_denotation.set_de_str(de_str);
		_reification.set_number(rei_num);
		_next = end();
	}
	SDFSign::SDFSign(wstring de_str, bool rei_bool): _s_start(-1),
		_s_end(-1),
		_v_start(-1),
		_v_end(-1),
		_parent(0),
		_next_sign(0) {
		int type = rei_bool == true ? SDF_TRUE : SDF_FALSE;
		_reification.set_type(type);
		_denotation.set_de_str(de_str);
		_reification.set_bool(rei_bool);
		_next = end();
	}
	SDFSign* SDFSign::next() {
		/* queit condition for recursive */
		if (_next == end() ){
			return 0;
		}	
		SDFSign* r = 0;
		if (_next_sign == *_next) {
			r = (*_next)->next_start();
		}else {
			r = (*_next)->next();
		}
		if ( r != 0) {
			_next_sign = r;
			return r;
		}else {
			++_next;
			_next_sign = *_next;
			return _next == end() ? 0 :* _next;
		}

	}

	SDFSign* SDFSign::next_start() {
		if ( empty() )
			return 0;
		else {
			_next = begin();
			_next_sign = *begin();
			return _next_sign;
		}
	}

	SDFSign::~SDFSign() {

	}
}